#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：turbo 
@File    ：yaml_config.py
@Author  ：赵加响
@Date    ：2023/3/31 14:58 
@Desc    ：
"""
import os
from pathlib import Path

import yaml

from utils.crypto.handler import AESCryptoHandler


class GetConfig:
    def __init__(self):
        base_dir = Path(__file__).resolve().parent.parent
        with open(os.path.join(base_dir, 'config.yaml'), 'r', encoding='utf-8') as env_file:
            self.env = yaml.load(env_file, Loader=yaml.FullLoader)

    def get_config(self, key):
        return self.env[key]

    def get_mysql_config(self):
        return self.get_config('mysql')

    def get_crypto_db_config(self, db='mysql'):
        config = self.get_config(db)
        crypto = AESCryptoHandler()
        config['PASSWORD'] = crypto.decrypt(config['PASSWORD'])
        return config

    def get_system_config(self):
        return self.get_config('system')

    def get_jwt_config(self):
        return self.get_config('jwt')

    def get_global_logging(self):
        return self.get_config('global_logging')

    def get_email_config(self):
        return self.get_config('email')
